package com.adtouch.shoppingcart;
 
import java.util.List;
import java.util.Vector;
 
import android.content.res.Resources;
 
public class ShoppingCartHelper {
  
 public static final String PRODUCT_INDEX = "PRODUCT_INDEX";
  
 private static List<Product> catalog;
 private static List<Product> cart;
  
/* public static List<Product> getCatalog(Resources res){
  if(catalog == null) {
   catalog = new Vector<Product>();
   catalog.add(new Product("Dead or Alive", res
     .getDrawable(R.drawable.deadoralive),
     "Dead or Alive by Tom Clancy with Grant Blackwood", 29.99));
   catalog.add(new Product("Switch", res
     .getDrawable(R.drawable.switchbook),
     "Switch by Chip Heath and Dan Heath", 24.99));
   catalog.add(new Product("Watchmen", res
     .getDrawable(R.drawable.watchmen),
     "Watchmen by Alan Moore and Dave Gibbons", 14.99));
  }
   
  return catalog;
 }*/
  
 public static List<Product> getCart()
 {
	  
	 return cart;
}

 public static void addtocart(Product product)
 {
	 if(cart == null) 
		   cart = new Vector<Product>();
	 
	 cart.add(product);
 }
 public static boolean search(Product product)
 {
	 int i;
	 for(i=0;i<cart.size();i++)
	 {
		 if(product.getDescription().equalsIgnoreCase(cart.get(i).description))
		return true;
	 
	 }
	 return false;
 }
 public static void addQuantity(Product product)
 {
	 int i;
	 for (i=0;i<cart.size();i++)
	 {
		 if(product.getDescription().equalsIgnoreCase(cart.get(i).description))
		 {
			 cart.get(i).setQuantity(cart.get(i).getQuantity()+1);
			 break;
		 }
	 }
 }
 public static void emptycart()
 {
	 int i;
	 if(cart!=null)
	 {
		 for (i=0;i<cart.size();i++)
		 cart.remove(i);
	 }
 }
 public static void removeitem(String desc)
 {
	 int i;
	 int temp;
	 for (i=0;i<cart.size();i++)
	 {
		 if(desc.equalsIgnoreCase(cart.get(i).description))
		 {
			 temp=cart.get(i).getQuantity();
			 if(temp==1)
				 cart.remove(i);
			 else
				 cart.get(i).setQuantity(temp-1);
			 
			 break;
		 }
	 }
	 
 }
 
}